package com.viettel.pon.httpclient;

import java.io.ByteArrayInputStream;
import java.io.File;

import android.util.Log;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.RequestParams;
import com.turbomanage.httpclient.AsyncCallback;
import com.turbomanage.httpclient.ParameterMap;
import com.turbomanage.httpclient.android.AndroidHttpClient;

public class HttpBasicClientHelperBK {

    // duong dan chung
    private static final String BASE_URL = "http://10.58.71.141:8999";

    // private static final String BASE_URL = "http://10.58.71.141:9012";
    // private static final String BASE_URL = "http://192.168.208.78:8084";

    // tim kiem su co
    private static final String SEARCH_TICKET = "/QLCTKT/rest/ntmsController/onSearchTicket";

    // chi tiet su co
    private static final String SEARCH_TICKET_DETAIL = "/QLCTKT/rest/ntmsController/onSearchTicketDetail";

    // Cap nhat cong viec con
    private static final String UPDATE_CHILD_TASK = "/QLCTKT/rest/ntmsController/onUpdateChildTask";

    // Tao cong viec con
    private static final String CREATE_CHILD_TASK = "/QLCTKT/rest/ntmsController/onCreateChildTask";

    // Cap nhat hoan thanh
    private static final String UPDATE_TROUBLE_COMPLETE = "/QLCTKT/rest/ntmsController/onUpdateTroubleComplete";

    // Cap nhat tam dong
    private static final String UPDATE_TROUBLE_TEMP = "/QLCTKT/rest/ntmsController/onUpdateTroubleTemp";

    // Cap nhat tiendo
    private static final String ON_UPDATE_PROCESS = "/QLCTKT/rest/ntmsController/onUpdateProcess";

    // Cap nhat su co
    private static final String PRE_UPDATE = "/QLCTKT/rest/ntmsController/onPreUpdate";

    // chuan bi tao cong viec con
    private static final String onPreInsertChildTask = "/QLCTKT/rest/ntmsController/onPreInsertChildTask";

    // --- giao su co cho nhan vien ----//
    private static final String onAssignTicket = "/QLCTKT/rest/ntmsController/onAssignTicket";

    // --- lay su co cc ----//
    private static final String onGetReasonCC = "/QLCTKT/rest/ntmsController/onGetReasonCC";

    // ------------------ dich vu co dinh -----------------//

    // chi tiet cong viec
    private static final String onSearchDVCDDetail = "/QLCTKT/rest/dvcdController/onSearchDVCDDetail";

    // chuan bi cap nhat cong viec khao sar
    private static final String onPreUpdateKSDVCD = "/QLCTKT/rest/dvcdController/onPreUpdateKSDVCD";

    // cap nhat cong viec khao sat
    private static final String onUpdateKSDVCD = "/QLCTKT/rest/dvcdController/onUpdateKSDVCD";

    // cap nhat tam hoan
    private static final String onUpdateDelayChildTask = "/QLCTKT/rest/dvcdController/onUpdateDelayChildTask";

    // cap nhat cong viec con ( keo cap/ han noi)
    private static final String onUpdateChildTask = "/QLCTKT/rest/dvcdController/onUpdateChildTask";

    // cap nhat cong viec nghiem thu ki thuat
    private static final String onUpdateTKDVCD = "/QLCTKT/rest/dvcdController/onUpdateTKDVCD";

    // cap nhat cong viec con dau noi tong dai
    private static final String onUpdateDeloyTask = "/QLCTKT/rest/dvcdController/onUpdateDeloyTask";

    // chuan bi cap nhat cong viec li do ton
    private static final String onPreUpdateTKDVCD = "/QLCTKT/rest/dvcdController/onPreUpdateTKDVCD";

    // ---- Man Hinh Test Dich Vu ---- //
    // load spin Indoor
    private static final String getListOdfIndoor = "/QLCTKT/rest/dvcdController/getListOdfIndoor";

    // load spin Outdoor
    private static final String getOdfOutdoorList = "/QLCTKT/rest/dvcdController/getOdfOutdoorList";

    // load spin Coupler
    private static final String getCoupler = "/QLCTKT/rest/dvcdController/getCoupler";

    // cap nhat cong viec con test dich vu
    private static final String onUpdateTestTask = "/QLCTKT/rest/dvcdController/onUpdateTestTask";
    private static final String onGetStationByTaskId = "/QLCTKT/rest/dvcdController/onGetStationByTaskId";
    private static final String onDeviceByNetworkClass = "/QLCTKT/rest/dvcdController/getListDevice";
    private static final String onGetStationByDept = "/QLCTKT/rest/dvcdController/onGetStationByDept";

    // ---- login ---- //
    private static final String login = "/QLCTKT/rest/authen/login";

    // home
    private static final String onHomePage = "/QLCTKT/rest/ntmsController/onHomePage";

    private static AndroidHttpClient client = new AndroidHttpClient();
    private AsyncCallback asyncCallback;
    private MyJsonHttpResponseHandler handler;

    public HttpBasicClientHelperBK(AsyncCallback asyncCallback) {
	this.asyncCallback = asyncCallback;
    }
    
    public HttpBasicClientHelperBK(MyJsonHttpResponseHandler handler) {
	this.handler = handler;
    }

    public static void get(final String url, final AsyncCallback responseHandler, final ParameterMap params) {
	Log.i("Tuan", url);
	new Thread(new Runnable() {

	    public void run() {
		client.get(getAbsoluteUrl(BASE_URL, url), params, responseHandler);
	    }
	}).start();

    }

    public static void get(String url, AsyncCallback responseHandler) {
	Log.i("Tuan", url);
	client.get(url, null, responseHandler);
    }

//    public static void uploadImage(final String url, final AsyncCallback responseHandler, final RequestParams params, byte[] byteArray, MyJsonHttpResponseHandler jsonHandler) {
////	RequestParams params = new RequestParams();
////	params.put("sso_id", preferenceHelper.getUserId());
////	params.put("hash", preferenceHelper.getHash());
////
////	params.put("picture", new ByteArrayInputStream(byteArray), "image.jpg");
//
//	AsyncHttpClient client = new AsyncHttpClient();
//	client.
//	client.post("http://vchat.vn/service/upload_image.php", params, new MyJsonHttpResponseHandler() {
//
//	    @Override
//	    public void onFailure(Throwable error) {
//		super.onFailure(error);
////		Toast.makeText(ChatActivity.this, "Request failed.", Toast.LENGTH_SHORT).show();
//	    }
//
//	    @Override
//	    public void onSuccess(JSONObject re) {
//		try {
//		    String error = re.getString("error");
//
//		    if (!error.equals("")) {
//			Log.i("DATA", "File qua lon");
//		    } else {
//			String data = re.getString("data");
//			Log.i("DATA", "URL tra ve: " + data);
//		    }
//
//		} catch (JSONException e) {
//		    e.printStackTrace();
//		}
//	    }
//	});
//    }

    public static void post(final String url, final AsyncCallback responseHandler, final ParameterMap params) {
	new Thread(new Runnable() {

	    public void run() {
		client.setConnectionTimeout(600000);
		client.post(getAbsoluteUrl(BASE_URL, url), params, responseHandler);

	    }
	}).start();

	Log.i("URL", "" + getAbsoluteUrl(BASE_URL, url));

    }

    public static void postWithHeader(String url, AsyncCallback responseHandler, ParameterMap params) {

	/*
	 * try { String credentials = "vchat-mobile" + ":" +
	 * "I2o5VG0c5a5dnZ866Y8Sguthojavuw"; String base64EncodedCredentials =
	 * Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);
	 * client.addHeader("Authorization", "Basic " +
	 * base64EncodedCredentials);
	 * 
	 * client.post(getAbsoluteUrl(BASE_URL_VATGIA,url), params,
	 * responseHandler); } catch (Exception e) { e.printStackTrace(); }
	 */

    }

    private static String getAbsoluteUrl(String base, String relativeUrl) {
	return base + relativeUrl;
    }

    // --------search ticket------------//
    public void searchTicket(long userId, long status, long type) {
	ParameterMap params = new ParameterMap();
	params.put("userAssignId", String.valueOf(userId));
	params.put("status", String.valueOf(status));
	params.put("type", String.valueOf(type));
	post(SEARCH_TICKET, asyncCallback, params);
    }

    // ------ticket detail-----//
    public void getTicketDetail(long userId, String account, long ma_suco) {
	ParameterMap params = new ParameterMap();
	params.put("userAssignId", String.valueOf(userId));
	if (account != null) {
	    params.put("account", account);
	} else {
	    params.put("account", "");
	}
	params.put("troubleAssignId", String.valueOf(ma_suco));
	post(SEARCH_TICKET_DETAIL, asyncCallback, params);
    }

    // ----cap nhat cv c0n---//
    public void updateChildTask(long troubleWorkId, long status, String note) {
	ParameterMap params = new ParameterMap();
	params.put("troubleWorkId", String.valueOf(troubleWorkId));
	params.put("status", String.valueOf(status));
	if (note != null) {
	    params.put("note", note);
	} else {
	    params.put("note", "");
	}
	post(UPDATE_CHILD_TASK, asyncCallback, params);
    }

    // ---Tao cong viec con---//
    public void createChildTask(long troubleAssignId, long troubleId, String workName, long workType, long numberSupplies,
	    String note, long userAssignId, String deadline) {
	ParameterMap params = new ParameterMap();
	params.put("troubleAssignId", String.valueOf(troubleAssignId));
	params.put("troubleId", String.valueOf(troubleId));
	if (workName != null) {
	    params.put("workName", workName);
	} else {
	    params.put("workName", "");
	}
	params.put("workType", String.valueOf(workType));
	params.put("numberSupplies", String.valueOf(numberSupplies));
	if (note != null) {
	    params.put("note", note);
	} else {
	    params.put("note", "");
	}
	params.put("userAssignId", String.valueOf(userAssignId));
	if (deadline != null) {
	    params.put("deadline", deadline);
	} else {
	    params.put("deadline", "");
	}

	post(CREATE_CHILD_TASK, asyncCallback, params);
    }

    // ---Khoi tao cap nhat cong viec---//
    public void preUpdate(long troubleAssignId, long troubleId, String account, long userAssignId) {
	ParameterMap params = new ParameterMap();
	params.put("troubleAssignId", String.valueOf(troubleAssignId));
	params.put("troubleId", String.valueOf(troubleId));
	if (account != null) {
	    params.put("account", account);
	} else {
	    params.put("account", "");
	}
	params.put("userAssignId", String.valueOf(userAssignId));
	post(PRE_UPDATE, asyncCallback, params);
    }

    // cap nhat tam dong
    public void updateTroubleTemp(long troubleAssignId, long troubleId, String descripton, String processNew, long reasonClose,
	    String content, String solution, long causeType, String appointmentTime, long userAssignId, String reasonDetail) {
	ParameterMap params = new ParameterMap();
	params.put("troubleAssignId", String.valueOf(troubleAssignId));
	params.put("troubleId", String.valueOf(troubleId));
	if (descripton != null) {
	    params.put("descripton", descripton);
	} else {
	    params.put("descripton", "");
	}
	if (processNew != null) {
	    params.put("processNew", processNew);
	} else {
	    params.put("processNew", "");
	}

	params.put("reasonClose", String.valueOf(reasonClose));

	if (content != null) {
	    params.put("content", content);
	} else {
	    params.put("content", "");
	}

	if (solution != null) {
	    params.put("solution", solution);
	} else {
	    params.put("solution", "");
	}

	params.put("causeType", String.valueOf(causeType));
	params.put("appointmentTime", appointmentTime);
	params.put("userAssignId", String.valueOf(userAssignId));

	if (reasonDetail != null) {
	    params.put("reasonDetail", reasonDetail);
	} else {
	    params.put("reasonDetail", "");
	}
	post(UPDATE_TROUBLE_TEMP, asyncCallback, params);
    }

    // cap nhat hoanthanh
    public void onUpdateTroubleComplete(long troubleAssignId, long troubleId, long causeType, String startTime, String endTime,
	    long NNCC, long userAssignId, String solution, String lstSupplies, String reasonDetail, String reasonGroupCcName) {
	ParameterMap params = new ParameterMap();

	params.put("troubleAssignId", String.valueOf(troubleAssignId));
	params.put("troubleId", String.valueOf(troubleId));
	params.put("causeType", String.valueOf(causeType));

	if (startTime != null) {
	    params.put("startTime", startTime);
	} else {
	    params.put("startTime", "");
	}

	if (endTime != null) {
	    params.put("endTime", endTime);
	} else {
	    params.put("endTime", "");
	}

	params.put("NNCC", String.valueOf(NNCC));
	params.put("userAssignId", String.valueOf(userAssignId));

	if (solution != null) {
	    params.put("solution", solution);
	} else {
	    params.put("solution", "");
	}

	if (lstSupplies != null) {
	    params.put("lstSupplies", lstSupplies);
	} else {
	    params.put("lstSupplies", "");
	}

	if (reasonDetail != null) {
	    params.put("reasonDetail", reasonDetail);
	} else {
	    params.put("reasonDetail", "");
	}

	if (reasonGroupCcName != null) {
	    params.put("groupCCName", reasonGroupCcName);
	} else {
	    params.put("groupCCName", "");
	}

	post(UPDATE_TROUBLE_COMPLETE, asyncCallback, params);
    }

    // cap nhat tiendo
    public void onUpdateProcess(long troubleAssignId, long troubleId, long userAssignId, String processNew, String note) {
	ParameterMap params = new ParameterMap();
	params.put("troubleAssignId", String.valueOf(troubleAssignId));
	params.put("troubleId", String.valueOf(troubleId));
	params.put("userAssignId", String.valueOf(userAssignId));

	if (processNew != null) {
	    params.put("processNew", processNew);
	} else {
	    params.put("processNew", "");
	}

	if (note != null) {
	    params.put("note", note);
	} else {
	    params.put("note", "");
	}

	post(ON_UPDATE_PROCESS, asyncCallback, params);
    }

    // tao cong viec con
    public void onCreateChildTask(long workType, String numberSupplies, String note, long userAssignId, String workName,
	    long troubleId, long troubleAssignId) {
	ParameterMap params = new ParameterMap();

	params.put("workType", String.valueOf(workType));
	params.put("numberSupplies", numberSupplies);

	if (note != null) {
	    params.put("note", note);
	} else {
	    params.put("note", "");
	}

	params.put("userAssignId", String.valueOf(userAssignId));

	if (note != null) {
	    params.put("workName", workName);
	} else {
	    params.put("workName", "");
	}

	params.put("troubleId", String.valueOf(troubleId));
	params.put("troubleAssignId", String.valueOf(troubleAssignId));
	post(CREATE_CHILD_TASK, asyncCallback, params);
    }

    // Chuan bi tao cong viec con
    public void onPreInsertChildTask(String account, long userAssignId, long troubleAssignId) {
	ParameterMap params = new ParameterMap();
	if (account != null) {
	    params.put("account", account);
	} else {
	    params.put("account", "");
	}
	params.put("userAssignId", String.valueOf(userAssignId));
	params.put("troubleAssignId", String.valueOf(troubleAssignId));
	post(onPreInsertChildTask, asyncCallback, params);
    }

    // --------------DVCD-----------------//

    // Chi tiet cong viec
    public void onSearchDVCDDetail(long taskId, String account) {
	ParameterMap params = new ParameterMap();
	params.put("taskId", String.valueOf(taskId));
	if (account != null) {
	    params.put("account", account);
	} else {
	    params.put("account", "");
	}
	post(onSearchDVCDDetail, asyncCallback, params);
    }

    // Chuan bi cap nhat cong viec khaor sat
    public void onPreUpdateKSDVCD(long userAssignId, String account, String serviceCode, long taskId) {
	ParameterMap params = new ParameterMap();
	params.put("userAssignId", String.valueOf(userAssignId));
	if (account != null) {
	    params.put("account", account);
	} else {
	    params.put("account", "");
	}

	if (serviceCode != null) {
	    params.put("serviceCode", serviceCode);
	} else {
	    params.put("serviceCode", "");
	}

	params.put("taskId", String.valueOf(taskId));
	post(onPreUpdateKSDVCD, asyncCallback, params);
    }

    // cap nhat cong viec khao sat
    public void onUpdateKSDVCD(long userAssignId, String account, long taskId, long newProgress, long reasonFail,
	    long surveyResult, String surveyNote, String listStock, long connectorId, String listMerchandise) {
	ParameterMap params = new ParameterMap();

	params.put("userAssignId", String.valueOf(userAssignId));

	if (account != null) {
	    params.put("account", account);
	} else {
	    params.put("account", "");
	}

	params.put("taskId", String.valueOf(taskId));
	params.put("newProgress", String.valueOf(newProgress));
	params.put("reasonFail", String.valueOf(reasonFail));
	params.put("surveyResult", String.valueOf(surveyResult));

	if (surveyNote != null) {
	    params.put("surveyNote", surveyNote);
	} else {
	    params.put("surveyNote", "");
	}

	if (listStock != null) {
	    params.put("listStock", listStock);
	} else {
	    params.put("listStock", "");
	}

	params.put("connectorId", String.valueOf(connectorId));

	if (listMerchandise != null) {
	    params.put("listMerchandise", listMerchandise);
	} else {
	    params.put("listMerchandise", "");
	}

	String[] keys = { "userAssignId", "account", "taskId", "newProgress", "reasonFail", "surveyResult", "surveyNote",
		"listStock", "connectorId", "listMerchandise" };

	for (int i = 0; i < keys.length; i++) {
	    Log.e("PARAM", keys[i] + "=" + params.get(keys[i]));
	}

	post(onUpdateKSDVCD, asyncCallback, params);

    }

    // cap nhat tam hoan
    public void onUpdateDelayChildTask(long userAssignId, long taskId, long newProgress, String noteReason, String reasonId,
	    String otherReason) {
	ParameterMap params = new ParameterMap();
	params.put("userAssignId", String.valueOf(userAssignId));
	params.put("taskId", String.valueOf(taskId));
	params.put("newProgress", String.valueOf(newProgress));

	if (noteReason != null) {
	    params.put("noteReason", noteReason);
	} else {
	    params.put("noteReason", "");
	}

	if (reasonId != null) {
	    params.put("reasonId", reasonId);
	} else {
	    params.put("reasonId", "");
	}

	if (otherReason != null) {
	    params.put("otherReason", otherReason);
	} else {
	    params.put("otherReason", "");
	}

	post(onUpdateDelayChildTask, asyncCallback, params);
    }

    // cap nhat cong viec con keo cap/han noi
    public void onUpdateChildTask(long userAssignId, long taskId, long newProgress, String note, String listMerchandise) {
	ParameterMap params = new ParameterMap();
	params.put("userAssignId", String.valueOf(userAssignId));
	params.put("taskId", String.valueOf(taskId));
	params.put("newProgress", String.valueOf(newProgress));

	if (note != null) {
	    params.put("note", note);
	} else {
	    params.put("note", "");
	}

	if (listMerchandise != null) {
	    params.put("listMerchandise", listMerchandise);
	} else {
	    params.put("listMerchandise", "");
	}

	post(onUpdateChildTask, asyncCallback, params);
    }

    // cap nhat cog viec nghiem thu ky thuat
    public void onUpdateTKDVCD(long userAssignId, long taskId, byte[] BBNT, byte[] BBBGTB, String note,  String listStock) {
	RequestParams params = new RequestParams();
	params.put("userAssignId", String.valueOf(userAssignId));
	params.put("taskId", String.valueOf(taskId));
	params.put("BBNT", new ByteArrayInputStream(BBNT));
	params.put("BBBGTB", new ByteArrayInputStream(BBBGTB));
	params.put("note", note);
	params.put("listStock", listStock);

	AsyncHttpClient client = new AsyncHttpClient();
	client.setTimeout(600000);
	client.post(getAbsoluteUrl(BASE_URL, onUpdateTKDVCD), params, handler);
//	client.post("http://vchat.vn/service/upload_image.php", params, new MyJsonHttpResponseHandler() {
//	    @Override
//	    public void onFailure(Throwable error) {
//		super.onFailure(error);
////		Toast.makeText(ChatActivity.this, "Request failed.", Toast.LENGTH_SHORT).show();
//	    }
//
//	    @Override
//	    public void onSuccess(JSONObject re) {
//		try {
//		    String error = re.getString("error");
//
//		    if (!error.equals("")) {
//			Log.i("DATA", "File qua lon");
//		    } else {
//			String data = re.getString("data");
//			Log.i("DATA", "URL tra ve: " + data);
//		    }
//
//		} catch (JSONException e) {
//		    e.printStackTrace();
//		}
//	    }
//	});
    }

    // cap nhat li do ton
    public void onPreUpdateTKDVCD(long userAssignId, String account, String serviceCode, long taskId) {
	ParameterMap params = new ParameterMap();
	params.put("userAssignId", String.valueOf(userAssignId));

	if (account != null) {
	    params.put("account", account);
	} else {
	    params.put("account", "");
	}

	if (serviceCode != null) {
	    params.put("serviceCode", serviceCode);
	} else {
	    params.put("serviceCode", "");
	}

	params.put("taskId", String.valueOf(taskId));
	Log.i("DATA", String.valueOf(taskId));
	post(onPreUpdateTKDVCD, asyncCallback, params);
    }

    // cap nhat cong viec con dau noi tong dai
    public void onUpdateDeloyTask(long userAssignId, long taskId, String deviceInfo) {
	ParameterMap params = new ParameterMap();
	params.put("userAssignId", String.valueOf(userAssignId));
	params.put("taskId", String.valueOf(taskId));

	if (deviceInfo != null) {
	    params.put("deviceInfo", deviceInfo);
	} else {
	    params.put("deviceInfo", "");
	}

	post(onUpdateDeloyTask, asyncCallback, params);
    }

    public void onUpdateDeloyTask(long userAssignId, long taskId, String note, String deviceInfo) {
	ParameterMap params = new ParameterMap();
	params.put("userAssignId", String.valueOf(userAssignId));
	params.put("taskId", String.valueOf(taskId));

	if (note != null) {
	    params.put("note", note);
	} else {
	    params.put("note", "");
	}

	if (deviceInfo != null) {
	    params.put("deviceInfo", deviceInfo);
	} else {
	    params.put("deviceInfo", "");
	}

	post(onUpdateDeloyTask, asyncCallback, params);
    }

    // pgd giao ticket
    public void onAssignTicket(long troubleAssignId, long userAssignId, String note, String assignTimeTemp) {
	ParameterMap params = new ParameterMap();
	params.put("troubleAssignId", String.valueOf(troubleAssignId));
	params.put("userAssignId", String.valueOf(userAssignId));
	if (note != null) {
	    params.put("note", note);
	} else {
	    params.put("note", "");
	}

	if (assignTimeTemp != null) {
	    params.put("assignTimeTemp", assignTimeTemp);
	} else {
	    params.put("assignTimeTemp", "");
	}

	post(onAssignTicket, asyncCallback, params);
    }

    // login
    public void login(String username, String password) {
	ParameterMap params = new ParameterMap();

	if (username != null) {
	    params.put("username", username);
	} else {
	    params.put("username", "");
	}

	if (password != null) {
	    params.put("password", password);
	} else {
	    params.put("password", "");
	}

	post(login, asyncCallback, params);
    }

    // login
    public void onGetReasonCC(long userAssignId, long troubleId) {
	ParameterMap params = new ParameterMap();
	params.put("userAssignId", String.valueOf(userAssignId));
	params.put("troubleId", String.valueOf(troubleId));
	post(onGetReasonCC, asyncCallback, params);
    }

    public void getListOdfIndoor(long userAssignId, String stationCode) {
	ParameterMap params = new ParameterMap();
	params.put("userAssignId", String.valueOf(userAssignId));

	if (stationCode != null) {
	    params.put("stationCode", stationCode);
	} else {
	    params.put("stationCode", "");
	}

	post(getListOdfIndoor, asyncCallback, params);
    }

    public void getOdfOutdoorList(long userAssignId, String odfIndoorId) {
	ParameterMap params = new ParameterMap();
	params.put("userAssignId", String.valueOf(userAssignId));

	if (odfIndoorId != null) {
	    params.put("odfIndoorId", odfIndoorId);
	} else {
	    params.put("odfIndoorId", "");
	}

	post(getOdfOutdoorList, asyncCallback, params);
    }

    public void getCoupler(long userAssignId, String odfIndoorId, String account) {
	ParameterMap params = new ParameterMap();
	params.put("userAssignId", String.valueOf(userAssignId));

	if (odfIndoorId != null) {
	    params.put("odfIndoorId", odfIndoorId);
	} else {
	    params.put("odfIndoorId", "");
	}

	if (account != null) {
	    params.put("account", account);
	} else {
	    params.put("account", "");
	}
	post(getCoupler, asyncCallback, params);
    }

    public void onUpdateTestTask(long userAssignId, long taskId, String note, String peripheralInfo) {
	ParameterMap params = new ParameterMap();
	params.put("userAssignId", String.valueOf(userAssignId));
	params.put("taskId", String.valueOf(taskId));

	if (note != null) {
	    params.put("note", note);
	} else {
	    params.put("note", "");
	}

	if (peripheralInfo != null) {
	    params.put("peripheralInfo", peripheralInfo);
	} else {
	    params.put("peripheralInfo", "");
	}

	post(onUpdateTestTask, asyncCallback, params);
    }

    public void onGetStationByDept(long userAssignId, String deparmentId) {
	ParameterMap params = new ParameterMap();
	params.put("userAssignId", String.valueOf(userAssignId));
	params.put("departmentId", String.valueOf(deparmentId));
	post(onGetStationByDept, asyncCallback, params);
    }

    public void onDeviceByNetworkClass(long userAssignId, String stationCode, String networkClass) {
	ParameterMap params = new ParameterMap();
	params.put("userAssignId", String.valueOf(userAssignId));
	params.put("stationCode", stationCode == null ? "" : stationCode);
	params.put("networkClass", networkClass == null ? "" : networkClass);
	post(onDeviceByNetworkClass, asyncCallback, params);
    }

    public void onHomePage(long userAssignId) {
	ParameterMap params = new ParameterMap();
	params.put("userAssignId", String.valueOf(userAssignId));
	post(onHomePage, asyncCallback, params);
    }

    public void onGetStationByTaskId(long userAssignId, long taskId) {
	ParameterMap params = new ParameterMap();
	params.put("userAssignId", String.valueOf(userAssignId));
	params.put("taskId", String.valueOf(taskId));
	post(onGetStationByTaskId, asyncCallback, params);
    }
}
